package me.zk.practice1.s;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @Author: zhang kai
 * @Date: 2023/05/05
 * @Description:
 */
public class S9 {
    public static void main(String[] args) {
        System.out.println(eraseOverlapIntervals(new int[][]{{1,2},{1,2},{1,2}}));
    }

    public static int eraseOverlapIntervals(int[][] intervals){
        if (intervals.length == 0) {
            return 0;
        }
        Arrays.sort(intervals,(Comparator.comparingInt(o -> o[1])));
        int count = 0;
        int pre = intervals[0][1];
        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i][0] < pre) {
                count++;
            } else {
                pre = intervals[i][1];
            }
        }
        return count;
    }
}
